package com.guiji.quartz.formatter;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ReUtil;
import us.codecraft.webmagic.model.formatter.ObjectFormatter;

import java.util.Date;
import java.util.List;

/**
 * @program: cms-vue-plus
 * @description:
 * @author: gaoX
 * @create: 2021-10-12 17:56
 **/
public class DateFormatterIST implements ObjectFormatter<Date> {
	@Override
	public Date format(String raw) throws Exception {
		Date date = null;
		try {
			List<String> allGroup1 = ReUtil.findAllGroup0("Updated.*?IST",raw);
			String s = allGroup1.get(0).replaceAll("Updated:","").trim();
			String[] split = s.split(" ");
			String day = split[0];
			String mon;
			switch (split[1]){
				case "January" :mon="01";
					break;
				case "February" :mon="02";
					break;
				case "March" :mon="03";
					break;
				case "April" :mon="04";
					break;
				case "May" :mon="05";
					break;
				case "June" :mon="06";
					break;
				case "July" :mon="07";
					break;
				case "August" :mon="08";
					break;
				case "September" :mon="09";
					break;
				case "October" :mon="10";
					break;
				case "November" :mon="11";
					break;
				default :mon="12";
			}
			String year = split[2];
			String sfm = split[3];
			String t = year+"-"+mon+"-"+day+" "+sfm;
			date = DateUtil.parse(t).toJdkDate();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return date;
	}

	@Override
	public Class<Date> clazz() {
		return null;
	}

	@Override
	public void initParam(String[] extra) {

	}
}
